package com.sino.operation.service.business;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sino.operation.commons.ConstantValue;
import com.sino.operation.entity.BizExchangeInfo;
import com.sino.operation.peripheral.esc.request.EscAppHead;
import com.sino.operation.peripheral.esc.request.EscSysHead;
import com.sino.operation.peripheral.esc.request.LocalHead;
import com.sino.operation.peripheral.esc.request.cnaps2_000104.EscBodyED0001_04;
import com.sino.operation.peripheral.esc.request.cnaps2_000104.EscED0001_04Param;
import com.sino.operation.peripheral.esc.request.cnaps2_000104.EscFeesInfo0001_04;
import com.sino.operation.peripheral.esc.request.cnaps2_000104.EscUPPCdtTrfInf0001_04;
import com.sino.operation.util.EscRequestTestUtil;
import org.apache.logging.log4j.util.StringMap;

import java.math.BigDecimal;
import java.util.Map;

public class Exec_710302_Util {

    //将中心录入字段进行登记薄归集
    public static BizExchangeInfo CollectionHandle(Map<String, Map> date, BizExchangeInfo bizExchangeInfo) {
        String payAcc = date.get("PAY_ACC").get("value").toString();//付款人账号
        String payName = date.get("PAY_NAME").get("value").toString();//付款人姓名
        String payAddr = date.get("PAY_ADDR").get("value").toString();//付款人地址
        String amount = date.get("AMOUNT").get("value").toString();//金额
        String cerno = date.get("CERNO").get("value").toString();//凭证号码
        String cerdate = date.get("CERDATE").get("value").toString();//凭证号码
        String paypwd = date.get("PAYPWD").get("value").toString();//支付密码
        String recvAcc = date.get("RECV_ACC").get("value").toString();//收款人账号
        String recvName = date.get("RECV_NAME").get("value").toString();//收款人姓名
        String recvAddr = date.get("RECV_ADDR").get("value").toString();//收款人地址
        String businessKind = date.get("BUSINESS_KIND").get("value").toString();//业务类型
        String remarks = date.get("REMARKS").get("value").toString();//备注
        String grade = date.get("GRADE").get("value").toString();//优先级
        String recvBno = date.get("RECV_BNO").get("value").toString();//收款人行号
        String recvBname = date.get("RECV_BNAME").get("value").toString();//收款行行名
        String arriveWay = date.get("ARRIVE_WAY").get("value").toString();//到账方式
        bizExchangeInfo.setPayAcc(payAcc);
        bizExchangeInfo.setPayName(payName);
        bizExchangeInfo.setPayAddr(payAddr);
        bizExchangeInfo.setAmount(amount);
        bizExchangeInfo.setCerno(cerno);
        bizExchangeInfo.setCerdate(cerdate);
        bizExchangeInfo.setPaypwd(paypwd);
        bizExchangeInfo.setRecvAcc(recvAcc);
        bizExchangeInfo.setRecvName(recvName);
        bizExchangeInfo.setRecvAddr(recvAddr);
        bizExchangeInfo.setBusinessKind(businessKind);
        bizExchangeInfo.setRemarks(remarks);
        bizExchangeInfo.setGrade(grade);
        bizExchangeInfo.setRecvBno(recvBno);
        bizExchangeInfo.setRecvBname(recvBname);
        bizExchangeInfo.setArriveWay(arriveWay);
        return bizExchangeInfo;
    }

    //判重
    public static QueryWrapper<BizExchangeInfo> repeatJudge(BizExchangeInfo bizExchangeInfo) {
        QueryWrapper<BizExchangeInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("CERDATE", bizExchangeInfo.getTranDate() == null ? "" : bizExchangeInfo.getTranDate());
        wrapper.eq("AMOUNT", bizExchangeInfo.getAmount() == null ? "" : bizExchangeInfo.getAmount());
        wrapper.eq("PAY_ACC", bizExchangeInfo.getPayAcc() == null ? "" : bizExchangeInfo.getPayAcc());
        wrapper.eq("RECV_BNO", bizExchangeInfo.getRecvAccno() == null ? "" : bizExchangeInfo.getRecvAccno());
        wrapper.eq("TRANS_CODE", bizExchangeInfo.getTransCode() == null ? "" : bizExchangeInfo.getTransCode());
        wrapper.eq("RECV_ACC", bizExchangeInfo.getRecvAcc() == null ? "" : bizExchangeInfo.getRecvAcc());
        wrapper.eq("CERNO", bizExchangeInfo.getCerno() == null ? "" : bizExchangeInfo.getCerno());
        wrapper.ne("JOURNAL_NO", bizExchangeInfo.getJournalNo());
        return wrapper;
    }
    //普通汇兑记账
    public static EscED0001_04Param ed0001_04ParamHandle(BizExchangeInfo bizExchangeInfo,String escToken){
        EscED0001_04Param escED0001_04Param = new EscED0001_04Param();
        EscBodyED0001_04 escBodyED0001_04 = new EscBodyED0001_04();
        EscUPPCdtTrfInf0001_04 escUPP = new EscUPPCdtTrfInf0001_04();
        EscFeesInfo0001_04 escFeesInfo0001_04 = new EscFeesInfo0001_04();
        String amount = bizExchangeInfo.getAmount();//金额
        String poundage = bizExchangeInfo.getPoundage();//手续费
        String payAcc = bizExchangeInfo.getPayAcc();//付款人账号
        String payName = bizExchangeInfo.getPayName();//付款人姓名
        String payAddr = bizExchangeInfo.getPayAddr();//付款人地址
        String payBno = bizExchangeInfo.getPayBno();//付款人行号
        String payBname = bizExchangeInfo.getPayBname();//付款人行名
        String accty = bizExchangeInfo.getAccty();//账号类型
        String expath = bizExchangeInfo.getExpath();//汇路号
        String bsty = bizExchangeInfo.getBsty();//业务类型
        String businessKind = bizExchangeInfo.getBusinessKind();//业务种类
        String recvAcc = bizExchangeInfo.getRecvAcc();//收款人账号
        String recvName = bizExchangeInfo.getRecvName();//收款人姓名
        String recvAccno = bizExchangeInfo.getRecvAccno();//收款人
        String recvAddr = bizExchangeInfo.getRecvAddr();//收款人地址
        String currency = bizExchangeInfo.getCurrency();//币种
        String remarks = bizExchangeInfo.getRemarks();//备注
        String grade = bizExchangeInfo.getGrade();//优先级
        String proxDno = bizExchangeInfo.getProxDno();//代理人证件号
        String proxDty = bizExchangeInfo.getProxDty();//代理人证件类型
        String proxName = bizExchangeInfo.getProxName();//代理人姓名
        String wdmd = bizExchangeInfo.getWdmd();//支取方式
        String docty = bizExchangeInfo.getDocty();//证件类型
        String docno = bizExchangeInfo.getDocno();//证件号
        String paypwd = bizExchangeInfo.getPaypwd();//支付密码
        String certy = bizExchangeInfo.getCerty();//凭证种类
        String cerno = bizExchangeInfo.getCerno();//凭证号
        String cerdate = bizExchangeInfo.getCerdate();//凭证日期
        String blklistseqNo = bizExchangeInfo.getBlklistseqNo();//黑名单流水号
        escUPP.setActy(accty);
        BigDecimal am=new BigDecimal(amount);
        escUPP.setAmount(am);
        escUPP.setPaypathcode(expath);
        escUPP.setBusikind(businessKind);
        escUPP.setBusitype(bsty);
        escUPP.setCurrency(currency);
        escUPP.setDlidno(proxDno);
        escUPP.setDlidtype(proxDty);
        escUPP.setDlname(proxName);
        escUPP.setPayeeacc(recvAcc);
        escUPP.setPayeename(recvName);
        escUPP.setPayeeaddr(recvAddr);
        escUPP.setPayeracc(payAcc);
        escUPP.setPayername(payName);
        escUPP.setPayeraddr(payAddr);
        escUPP.setPayeraccbank(payBno);
        escUPP.setPayeeaccbank(recvAccno);
        escUPP.setPostscript(remarks);
        escUPP.setPriority(grade);
        escUPP.setDrawtype(wdmd);
        escUPP.setDlname(proxName);
        escUPP.setDlidtype(proxDty);
        escUPP.setDlidno(proxDno);
        escUPP.setPayeridtype(docty);
        escUPP.setPayeridno(docno);
        escUPP.setPaypass(paypwd);
        escUPP.setVouchtype(certy);
        escUPP.setVochno(cerno);
        escUPP.setVouchdate(cerdate);
        escFeesInfo0001_04.setFeeamount(poundage);
        escBodyED0001_04.setBlklistseqno(blklistseqNo);
        escBodyED0001_04.setEscUPPCdtTrfInf0001_04(escUPP);
        escBodyED0001_04.setEscFeesInfo0001_04(escFeesInfo0001_04);
        escED0001_04Param.setEscBodyED000104(escBodyED0001_04);
        EscSysHead escSysHead = EscRequestTestUtil.getEscSysHead(bizExchangeInfo.getJournalNo());
        LocalHead localHead = EscRequestTestUtil.getLocalHead(ConstantValue.EXCHANGE_SX_CNAPS2_PB0001_04,escToken);
        EscAppHead appHead = EscRequestTestUtil.getAppHead();
        escED0001_04Param.setEscSysHead(escSysHead);
        escED0001_04Param.setLocalHead(localHead);
        escED0001_04Param.setEscAppHead(appHead);
        return escED0001_04Param;
    }
}
